package com.abel.bigwater.msg

import com.abel.bigwater.data.BcdString
import com.abel.bigwater.obsolete.JsonHelper
import com.alibaba.fastjson.annotation.JSONField
import java.util.*

class RtuMsg {
    /**
     * rtu-id, generally short-integer.
     */
    var station: String? = null

    /**
     * @see RtuMsgType
     */
    var msgType: String? = null

    /**
     * will be base64 in json.
     */
    var rawBinary: ByteArray? = null

    /**
     * in hex format.
     */
    var rawHex: String? = null
        get() = if (rawBinary != null) BcdString.hexString(rawBinary!!) else null

    /**
     * may be text for heart, realtime, etc.
     */
    var text: String? = null

    /**
     * remote client.
     */
    var source: String? = null

    /**
     * local server.
     */
    var target: String? = null

    @JSONField(format = JsonHelper.FULL_DATE_FORMAT)
    var recvTime: Date? = null

    var firmId: String? = null

    var firmCode: String? = null

    var serverPort: Int? = null
}

enum class RtuMsgType {
    DATA_BIN,

    DATA_TXT,

    HEART,

    WARN,

    STATUS;
}